package com.hl.security.config;

import com.hl.security.UserAuthenticationFailureHandler;
import com.hl.security.UserAuthenticationSuccessHandler;
import com.hl.security.UserLogoutSuccessHandler;
import com.hl.security.UserServicesImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.encoding.BasePasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * Created by aaron on 2017/1/17.
 */
public class SecurityConfigInfo {
    private UserLogoutSuccessHandler userLogoutSuccessHandler;
    private UserAuthenticationFailureHandler userAuthenticationFailureHandler;
    private UserAuthenticationSuccessHandler userAuthenticationSuccessHandler;
    private BasePasswordEncoder passwordEncoder;
    private UserDetailsService userDetailsService;

    private static final UserLogoutSuccessHandler defaultUserLogoutSuccessHandler = new UserLogoutSuccessHandler();
    private static final UserAuthenticationFailureHandler defaultUserAuthenticationFailureHandler = new UserAuthenticationFailureHandler();
    private static final UserAuthenticationSuccessHandler defaultUserAuthenticationSuccessHandler = new UserAuthenticationSuccessHandler();
    private static final BasePasswordEncoder defaultPasswordEncoder = new ShaPasswordEncoder(256);
    private static final UserDetailsService defaultUserDetailsService=new UserServicesImpl();

    public SecurityConfigInfo(UserLogoutSuccessHandler userLogoutSuccessHandler, UserAuthenticationFailureHandler userAuthenticationFailureHandler, UserAuthenticationSuccessHandler userAuthenticationSuccessHandler, BasePasswordEncoder passwordEncoder, UserDetailsService userDetailsService) {
        this.userLogoutSuccessHandler = userLogoutSuccessHandler;
        this.userAuthenticationFailureHandler = userAuthenticationFailureHandler;
        this.userAuthenticationSuccessHandler = userAuthenticationSuccessHandler;
        this.passwordEncoder = passwordEncoder;
        this.userDetailsService = userDetailsService;
    }

    public SecurityConfigInfo(UserDetailsService userDetailsService) {
        this(defaultUserLogoutSuccessHandler, defaultUserAuthenticationFailureHandler, defaultUserAuthenticationSuccessHandler, defaultPasswordEncoder, userDetailsService);
    }

    public SecurityConfigInfo() {
        this(defaultUserLogoutSuccessHandler, defaultUserAuthenticationFailureHandler, defaultUserAuthenticationSuccessHandler, defaultPasswordEncoder, defaultUserDetailsService);
    }

    public UserLogoutSuccessHandler getUserLogoutSuccessHandler() {
        return userLogoutSuccessHandler;
    }

    public void setUserLogoutSuccessHandler(UserLogoutSuccessHandler userLogoutSuccessHandler) {
        this.userLogoutSuccessHandler = userLogoutSuccessHandler;
    }

    public UserAuthenticationFailureHandler getUserAuthenticationFailureHandler() {
        return userAuthenticationFailureHandler;
    }

    public void setUserAuthenticationFailureHandler(UserAuthenticationFailureHandler userAuthenticationFailureHandler) {
        this.userAuthenticationFailureHandler = userAuthenticationFailureHandler;
    }

    public UserAuthenticationSuccessHandler getUserAuthenticationSuccessHandler() {
        return userAuthenticationSuccessHandler;
    }

    public void setUserAuthenticationSuccessHandler(UserAuthenticationSuccessHandler userAuthenticationSuccessHandler) {
        this.userAuthenticationSuccessHandler = userAuthenticationSuccessHandler;
    }

    public BasePasswordEncoder getPasswordEncoder() {
        return passwordEncoder;
    }

    public void setPasswordEncoder(BasePasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    public UserDetailsService getUserDetailsService() {
        return userDetailsService;
    }

    public void setUserDetailsService(UserDetailsService userDetailsService) {
        this.userDetailsService = userDetailsService;
    }
}
